package os;

import java.util.ArrayList;
import memory.Memory;

/**
 *
 * @author Paulius Dambrauskas
 */
public class Loader extends Process{
    ArrayList<ArrayList<String>> task;
    private int loaded = 0;
    @Override
    public void runProcess() {
        this.changeStepCell(step);
        switch(step){
            case 1:{
                //changeStepCell(1);
                OS.askRes("Pakrovimo paketas", selfId);
                incStep(1);
                break;
            }
            case 2:{
                //changeStepCell(2);
                OS.askRes("3 Kanalas", selfId);
                incStep(1);
                break;
            }
            case 3:{
                //changeStepCell(3);
                OS.window.processor.getCH3().setRegisterValue("1");
                task = (ArrayList<ArrayList<String>>) this.takeFromGivenResources("Pakrovimo paketas").value;                
                loaded = Memory.loadProgram(task);
                //loaded++;
                incStep(1);
                break;
            }
            case 4:{
                //changeStepCell(4);
                OS.freeRes(this.takeFromGivenResources("3 Kanalas"));
                OS.window.processor.getCH3().setRegisterValue("0");
                OS.freeRes(new ResourceElement("Loader darbo pabaiga", loaded));
                setStep(1);
            }
        }
    }
    
}
